#include "handy/handy/handy.h"
#include <algorithm>
#include <stdio.h>
#include <string>
#include <stdint.h>
#include "common.h"
#include "xudp.pb.h"

using namespace std;
using namespace handy;

int main() {
	setloglevel("INFO");
  setlogfile("test_server_tcp");
	EventBase base;
	Signal::signal(SIGINT, [&] { base.exit(); });

	TcpServerPtr s = TcpServer::startServer(&base, "", SERVER_PORT);
	exitif(s == NULL, "start tcp server failed");

	s->onConnCreate([] {
		TcpConnPtr con(new TcpConn);
		con->onMsg(new LengthCodec, [](const TcpConnPtr& con, Slice msg) {
			xmsg m;
			m.ParseFromArray(msg.data(), msg.size());
			info("id:%d,time:%ld", m.id(), util::timeMilli());
		});
		return con;
	});
	base.loop();
	info("program exited");
}
